﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace EMC.VISITOR.Core;

    /// <summary>
    /// API返回的Json模型（用于Select等需要返回数据集的场景）
    /// </summary>
    public class ResultJsonInfo<T> : ResultJsonBase
    {
        public ResultJsonInfo()
        {
            this.Status = ResultConfig.Ok;
            this.Info = ResultConfig.SuccessfulMessage;
            IsSuccess = true;
        }
        public ResultJsonInfo(bool flag = true)
        {
            if (flag)
            {
                Success();
            }
            else
            {
                Fail();
            }
        }

        #region field

        private T data;

        #endregion

        #region property

        /// <summary>
        /// 返回数据
        /// </summary>
        [Description("返回数据")]
        public T Data
        {
            get { return data; }
            set { data = value; }
        }

        public dynamic Other { get; set; }
        #endregion

        public void Success(string message = "")
        {
            this.Status = ResultConfig.Ok;
            if (!string.IsNullOrWhiteSpace(message))
                this.Info = message;
            else
                this.Info = ResultConfig.SuccessfulMessage;
            IsSuccess = true;
        }
        public void Fail(string message = "")
        {
            IsSuccess = false;
            this.Status = ResultConfig.Fail;
            if (!string.IsNullOrWhiteSpace(message))
                this.Info = message;
            else
                this.Info = ResultConfig.FailMessage;
        }
        public void ReturnOtherCode(string message = "", int? statusValue = null)
        {
            IsSuccess = false;
            if (statusValue.HasValue)
                this.Status = statusValue.Value;
            else
                this.Status = ResultConfig.OtherCode;
            if (!string.IsNullOrWhiteSpace(message))
                this.Info = message;
            else
                this.Info = string.Empty;
        }

        public void ReturnQAPostingCode(string message = "", int? statusValue = null)
        {
            IsSuccess = false;
            if (statusValue.HasValue)
                this.Status = statusValue.Value;
            else
                this.Status = ResultConfig.QAPostingCode;
            if (!string.IsNullOrWhiteSpace(message))
                this.Info = message;
            else
                this.Info = string.Empty;
        }
        public void NotData()
        {
            IsSuccess = true;
            this.Status = ResultConfig.NotData;
            this.Info = ResultConfig.NotFindData;
        }
    }


    /// <summary>
    /// ResultJsonBase
    /// </summary>
    public class ResultJsonBase
    {

        public ResultJsonBase()
        {

        }

        #region field
        private bool isSuccess;
        private int status;
        private string info;

        #endregion

        #region property

        /// <summary>
        /// 状态
        /// </summary>
        [Description("状态(0:失败 1:成功 2:没权限 3:token过期 99:其它状态)")]
        public int Status
        {
            get { return status; }
            set { status = value; }
        }

        /// <summary>
        /// 提示信息
        /// </summary>
        [Description("提示信息")]
        public string Info
        {
            get { return info; }
            set { info = value; }
        }

        public bool IsSuccess
        {
            get
            {
                if (Status == ResultConfig.Ok)
                    return true;
                else
                    return false;
            }
            set
            { isSuccess = value; }
        }

        #endregion
    }

    public class ResultConfig
    {
        /// <summary>
        /// 执行失败返回值("0")
        /// </summary>
        public static int Fail = 0;

        /// <summary>
        /// 执行成功返回值("1")
        /// </summary>
        public static int Ok = 1;
        /// <summary>
        /// 没权限
        /// </summary>
        public static int NoPower = 2;
        /// <summary>
        /// Token过期
        /// </summary>
        public static int TokenExpiration = 3;
        /// <summary>
        /// 没有数据
        /// </summary>
        public static int NotData = 4;

        public static int OtherCode = 99;

        public static int QAPostingCode = 110;

        /// <summary>
        /// 执行成功返回值提示("成功")
        /// </summary>
        public static string SuccessfulMessage = "操作成功！";

        /// <summary>
        /// 执行失败返回值提示（失败）
        /// </summary>
        public static string FailMessage = "操作失败！";

        public static string FailMessageForNoPower = "没有权限，操作失败，或在其它地方登录！";


        public static string FailMessageForSystem = "系统出错，操作失败！";

        public static string FailMessageForNotFound = "系统出错,404-NotFound！";

        public static string FailMessageForTokenExpiration = "非法Token,需重新登录!";

        public static string NotFindData = "没有查询到数据";
    }

